package com.ruoyi.different.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.different.domain.DifferentRete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.different.mapper.DifferentLoggingMapper;
import com.ruoyi.different.domain.DifferentLogging;
import com.ruoyi.different.service.IDifferentLoggingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 日志记录Service业务层处理
 * 
 * @author rocky
 * @date 2023-12-20
 */
@Service
public class DifferentLoggingServiceImpl extends ServiceImpl<DifferentLoggingMapper, DifferentLogging> implements IDifferentLoggingService
{
    @Autowired
    private DifferentLoggingMapper differentLoggingMapper;

    /**
     * 查询日志记录
     * 
     * @param logId 日志记录主键
     * @return 日志记录
     */
    @Override
    public DifferentLogging selectDifferentLoggingByLogId(Long logId)
    {
        return differentLoggingMapper.selectDifferentLoggingByLogId(logId);
    }

    /**
     * 查询日志记录列表
     * 
     * @param differentLogging 日志记录
     * @return 日志记录
     */
    @Override
   // @DataScope(deptAlias = "d", userAlias = "u")
    public List<DifferentLogging> selectDifferentLoggingList(DifferentLogging differentLogging)
    {
        return differentLoggingMapper.selectDifferentLoggingList(differentLogging);
    }

    /**
     * 新增日志记录
     * 
     * @param differentLogging 日志记录
     * @return 结果
     */
    @Override
    public int insertDifferentLogging(DifferentLogging differentLogging)
    {
        differentLogging.setCreateTime(DateUtils.getNowDate());
        return differentLoggingMapper.insertDifferentLogging(differentLogging);
    }

    /**
     * 修改日志记录
     * 
     * @param differentLogging 日志记录
     * @return 结果
     */
    @Override
    public int updateDifferentLogging(DifferentLogging differentLogging)
    {
        differentLogging.setUpdateTime(DateUtils.getNowDate());
        return differentLoggingMapper.updateDifferentLogging(differentLogging);
    }

    /**
     * 批量删除日志记录
     * 
     * @param logIds 需要删除的日志记录主键
     * @return 结果
     */
    @Override
    public int deleteDifferentLoggingByLogIds(Long[] logIds)
    {
        return differentLoggingMapper.deleteDifferentLoggingByLogIds(logIds);
    }

    /**
     * 删除日志记录信息
     * 
     * @param logId 日志记录主键
     * @return 结果
     */
    @Override
    public int deleteDifferentLoggingByLogId(Long logId)
    {
        return differentLoggingMapper.deleteDifferentLoggingByLogId(logId);
    }

    @Override
    public void cheak(DifferentLogging differentLogging) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (!SysUser.isAdmin(SecurityUtils.getUserId())&&differentLogging.getAssociationId()!=Long.valueOf(user.getDeptId()).intValue())
        {
            throw new ServiceException("没有权限访问用户数据！");

        }
    }

    @Override
    public void cheaks(List<DifferentLogging> differentLoggings) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        for (DifferentLogging differentLogging : differentLoggings) {
            //System.out.println(differentRete.getBranchId());
            //System.out.println(user.getDeptId());
            if (!SysUser.isAdmin(SecurityUtils.getUserId())&&differentLogging.getAssociationId()!=Long.valueOf(user.getDeptId()).intValue())
            {
                throw new ServiceException("没有权限访问用户数据！");

            }
        }

    }
}
